package com.spring.aop.study.aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

/**
 *
 *
 * @Description:
 * @Author: 梁飞
 * @Date: 2021-09-02 09:40
 */

@Slf4j
@Component
@Aspect
public class LogAspect {

    /**
     * 配置切入点
     */
    @Pointcut("@annotation(com.spring.aop.study.annotation.Log)")
    public void logPointcut() {
        // 该方法无方法体,主要为了让同类中其他方法使用此切入点
    }

    @Around("logPointcut()")
    public Object logAround(ProceedingJoinPoint joinPoint) throws Throwable {
        Signature signature = joinPoint.getSignature();
        Object[] args = joinPoint.getArgs();
        Object proceed = joinPoint.proceed();
        return proceed;
    }

    @Before("logPointcut()")
    public Object logBefore(JoinPoint joinPoint) throws Throwable {
        Object proceed = joinPoint.getSignature();
        return proceed;
    }

    @After("logPointcut()")
    public Object logAfter(JoinPoint joinPoint) throws Throwable {
        Object proceed = joinPoint.getSignature();
        return proceed;
    }

    @AfterReturning(pointcut = "logPointcut()",returning = "result")
    public Object logAfterReturning(JoinPoint joinPoint,Object result) throws Throwable {
        Object proceed = joinPoint.getArgs();
        return proceed;
    }

    @AfterThrowing(pointcut = "logPointcut()" ,throwing = "e")
    public Object logAfterThrowing(JoinPoint joinPoint,Exception e) throws Throwable {
        Object proceed = joinPoint.getSignature();
        return proceed;
    }


}
